// url is http://build.navicore.cn/view/Manual/job/NaviCoreMacBranch/
// so name is NaviCoreMacBranch
function getProjectNameByUrl(url) {
    var res = url.split("/");
    if (res.length >= 1 && res[res.length - 1] != "") {
        return res[res.length - 1];
    }
    else if (res.length >= 2) {
        return res[res.length - 2];
    }
    else {
        return "Please fill url";
    }
}

// @param http://build.navicore.cn mapbar 123456789
// @return http://mapbar:123456789@build.navicore.cn  
function construcUrlByNameAndToken(name, token, url) {
    var resUrl = url;
    var pos = resUrl.indexOf("://");
    if (pos != -1) {
        resUrl = resUrl.slice(0, pos + 3) + name + ':' + token + '@' + resUrl.slice(pos + 3);
    }
    if (resUrl.charAt(resUrl.length - 1) == '/') {
        resUrl = resUrl.slice(0, resUrl.length - 1);
    }
    return resUrl;
}

module.exports = {
    getProjectNameByUrl,
    construcUrlByNameAndToken
};